cmd line tutorials - gencmd

cmd line tutorials - gencmd

The history Command

Unix-Linux Mac

The history command is a built-in shell command that displays a list of commands that have been executed in the current terminal session. It is a useful tool for reviewing the commands that you have used, and for finding and re-executing commands that you have used in the past.

Syntax

The basic syntax for the history command is as follows:

history [options]

The options argument is a list of options that can be used to modify the behavior of the history command.

Examples

Display a list of all commands that have been executed in the current terminal session.

history

Display the last 10 commands that have been executed in the current terminal session:

history 10

Display the commands that contain the word “foo”:

history | grep foo

Re-execute the last command that was executed in the current terminal session.

!!

Re-execute the command that was executed two commands ago.

!2

For more information on the history command and its options, please see the man page for history.

Additional Tips

You can use the Ctrl+R keyboard shortcut to search the history interactively.

You can use the history command to save your history to a file. To do this, type the following command:

history > ~/.bash_history

This will save your history to the file ~/.bash_history. When you open a new terminal session, your history will be loaded from this file.

With gencmd

gencmd rerun third last command

  • !3